package com.lh.factory.absfactory.pizzastore.order;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import com.lh.factory.absfactory.pizzastore.pizza.Pizza;

public class OrderPizza {

	// 是聚合
	AbsFactory factory;

	//构造器

	public OrderPizza(AbsFactory factory) {
		setFactory(factory);
	}

	//指向子类实例化
	private void setFactory(AbsFactory factory) {
		Pizza pizza = null;

		String orderType; // 用户输入披萨

		this.factory = factory;

		do {

			orderType = getType();
			//可能是北京，或者是伦敦
			pizza = factory.createFactory(orderType);

			if (pizza != null) { //订购 ok
				pizza.prepare();
				pizza.bake();
				pizza.cut();
				pizza.box();
			}else {
				System.out.println("订购失败！");
				break;
			}

		} while (true);

	}

	// 写一个方法，可以获取客户希望订购的披萨种类
	private String getType() {
		try {
			BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
			System.out.println("input pizza 种类:");
			String str = strin.readLine();
			return str;
		} catch (IOException e) {
			e.printStackTrace();
			return "";
		}
	}
}
